<template>
    <div>
        <el-form ref="queryForm"  :inline="true" v-show="showSearch">
  
            <el-form-item label="" v-for="(item, index) in listFrom" :key="index">
                <span slot="label">{{ item.FIELD_CAPTION }} </span>
                <input_item :item="item" :listFrom="listFrom" @onChangeTap="onChangeTap" :inputType="1" @handleQuery="handleQuery" :inputParams="queryParams" :tenantCode="tenantCode"></input_item>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search"  @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh"  @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
import input_item from "@/components/input/index.vue"
export default {
    props: ['showSearch', 'listFrom', 'isShow','tenantCode'],
    components: { input_item },
    data() {
        return {
            queryParams: {},
            querylist: [],
        }
    },
    watch: {
        listFrom: {
            handler(valNew) {
                this.querylist = valNew
            },
            immediate: true,

        }

    },
    created() {

    },
    methods: {
        //onChangeTap时间
        onChangeTap(data) {
            var dataArr=""
            if(data.val!=undefined){  
                dataArr = data.queryParams;
            }else{
                dataArr = data;
            }
            if (this.queryParams.length > 0) {
                for (var i in this.queryParams) {
                    if (Object.keys(this.queryParams[i]).toString() == Object.keys(dataArr).toString()) {
                        this.queryParams.splice(i, 1)
                    }
                }
                this.queryParams = dataArr;
            } else {
                this.queryParams = dataArr;
            }

        },
        handleQuery() {
            var searchcolumn = []
            for (var k in this.listFrom) {
                for (var i in this.queryParams) {
                  if(this.queryParams[i] != null) {
                    if (this.listFrom[k].FIELD_NAME == i) {
                      if (this.listFrom[k].SHOWTYPE == 3&&this.listFrom[k].IS_QUERY==4) {
                        searchcolumn.push({
                          "queryType": this.listFrom[k].IS_QUERY,
                          "showType": this.listFrom[k].SHOWTYPE,
                          "column": this.listFrom[k].FIELD_NAME,
                          "value": this.queryParams[i][0],
                          "valueTwo": this.queryParams[i][1],
                        })
                      } else if (this.listFrom[k].SHOWTYPE == 7 || this.listFrom[k].SHOWTYPE == 8) {
                        searchcolumn.push({
                          "queryType": this.listFrom[k].IS_QUERY,
                          "showType": this.listFrom[k].SHOWTYPE,
                          "column": this.listFrom[k].FIELD_NAME+"_ID",
                          "value": this.queryParams[i+"_ID"],

                        })
                      } else {
                        searchcolumn.push({
                          "queryType": this.listFrom[k].IS_QUERY,
                          "showType": this.listFrom[k].SHOWTYPE,
                          "column": this.listFrom[k].FIELD_NAME,
                          "value": this.queryParams[i],

                        })
                      }
                    }
                  }


                }
            }

            this.$emit("handleQuery", searchcolumn)
        },
        //重置
        resetQuery() {
            this.queryParams = {};
            this.$emit("resetQuery")
        },


    }
}
</script>
